package com.sx.pipeline.ui.linepipe

import android.graphics.Color
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.google.android.material.tabs.TabLayoutMediator
import com.hjq.bar.TitleBar
import com.sx.pipeline.R
import com.sx.pipeline.app.base.CYBaseAppBarActivity
import com.sx.pipeline.arouth.RouteManager
import com.sx.pipeline.arouth.RoutePath
import com.sx.pipeline.databinding.ActTerritoryPageBinding
import com.sx.pipeline.ui.linepipe.adapter.LinePipePageAdapter
import com.sx.pipeline.ui.territory.adapter.TerritoryPageAdapter

/**
 * @Author: YY
 * @Date: 2022/8/3
 * @Desc: 负责区域 Page
 */
@Route(path = RoutePath.LinePipe.LINE_PIPE_PAGE)
class LinePipePageActivity: CYBaseAppBarActivity<ActTerritoryPageBinding, LinePipeVM>(R.layout.act_territory_page) {

    // 任务页面
    private lateinit var linePipePageAdapter: LinePipePageAdapter

    override fun initAppBar() {
        getTitleBar().title = "我的管线"
        getTitleBar().rightTitle = "导入"
        getTitleBar().setRightTitleSize(13f)
        getTitleBar().setRightTitleColor(Color.parseColor("#0188FF"))
    }

    override fun onRightClick(titleBar: TitleBar?) {
        RouteManager.LinePipe.intentToLinePipeFile()
    }

    override fun initData() {
        super.initData()
        // 初始化Tab
        initPager()
    }

    /**
     * 初始化ViewPager
     */
    private fun initPager() {
        if (mBinding.viewPager.adapter == null) {
            linePipePageAdapter = LinePipePageAdapter(
                mViewModel.getTerritoryTypeList(), supportFragmentManager, lifecycle
            )
        }
        mBinding.viewPager.offscreenPageLimit = mViewModel.getTerritoryTypeList().size
        mBinding.viewPager.adapter = linePipePageAdapter
        //绑定tabLayout和viewPager
        TabLayoutMediator(
            mBinding.tab, mBinding.viewPager,
            true, true
        ) { tab, position ->
            tab.text = mViewModel.getTerritoryTypeList()[position]
        }.attach()
    }
}